package io.gitee.guoguoleo.handler;

import cn.hutool.core.util.StrUtil;
import io.gitee.guoguoleo.model.ObjectMeta;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Setter
@Getter
public abstract class MetaHandler {

    private List<ObjectMeta> insertMetaHandlerList;

    private List<ObjectMeta> updateMetaHandlerList;

    public MetaHandler(){
        this.insertMetaHandlerList = new CopyOnWriteArrayList<>();
        this.updateMetaHandlerList = new CopyOnWriteArrayList<>();
    }

    public void setInsertHandler(String fieldName, Class<?> clazz, Object fieldVal) {
        insertMetaHandlerList.add(new ObjectMeta() {{
            setFieldName(StrUtil.toCamelCase(fieldName));
            setClazz(clazz);
            setFieldVal(fieldVal);
        }});
    }

    public void setUpdateHandler(String fieldName, Class<?> clazz, Object fieldVal) {
        updateMetaHandlerList.add(new ObjectMeta() {{
            setFieldName(StrUtil.toCamelCase(fieldName));
            setClazz(clazz);
            setFieldVal(fieldVal);
        }});
    }

    public abstract void startInsertHandler();

    public abstract void startUpdateHandler();


}
